package com.burst.reptile.common.utils;

import java.time.LocalDateTime;
import java.time.ZoneOffset;

import cn.hutool.core.date.DatePattern;

/**
 * 时间工具类
 * @author wujin
 *
 * @date: 2020年6月16日 下午1:22:39
 */
public class DateUtil extends cn.hutool.core.date.DateUtil{

	/**
	 * 判断目标日期距离当前日期多长时间
	 * 
	 * @param timeStamp 时间戳
	 * @return
	 */
	public static String convertTimeToFormat1(long timeStamp) {
		long curTime = System.currentTimeMillis() / (long) 1000;
		long time = curTime - timeStamp;
 
		if (time < 60 && time >= 0) {
			return "刚刚";
		} else if (time >= 60 && time < 3600) {
			return time / 60 + "分钟前";
		} else if (time >= 3600 && time < 3600 * 24) {
			return time / 3600 + "小时前";
		} else if (time >= 3600 * 24 && time < 3600 * 24 * 30) {
			return time / 3600 / 24 + "天前";
		} else if (time >= 3600 * 24 * 30 && time < 3600 * 24 * 30 * 12) {
			return time / 3600 / 24 / 30 + "个月前";
		} else if (time >= 3600 * 24 * 30 * 12) {
			return time / 3600 / 24 / 30 / 12 + "年前";
		} else {
			return "刚刚";
		}
	}
	
	/**
	 * 判断目标日期距离当前日期多长时间
	 * 
	 * @param timeStamp 时间戳
	 * @return
	 */
	public static String timeToFormat(LocalDateTime date) {
		
		long timeStamp = date.toEpochSecond(ZoneOffset.of("+8"));
		
		long curTime = System.currentTimeMillis() / (long) 1000;
		long time = curTime - timeStamp;
 
		if (time < 60 && time >= 0) {
			return "刚刚";
		} else if (time >= 60 && time < 3600) {
			return time / 60 + "分钟前";
		} else if (time >= 3600 && time < 3600 * 24) {
			return time / 3600 + "小时前";
		} else if (time >= 3600 * 24 && time < 3600 * 24 * 30) {
			return time / 3600 / 24 + "天前";
		} else if (time >= 3600 * 24 * 30 && time < 3600 * 24 * 30 * 12) {
			return DateUtil.format(date, "MM月dd日");
		} else if (time >= 3600 * 24 * 30 * 12) {
			return DateUtil.format(date, DatePattern.CHINESE_DATE_PATTERN);
		} else {
			return "刚刚";
		}
	}
	
	/**
	 * 判断目标日期距离当前日期多长时间
	 * 
	 * @param timeStamp 时间戳
	 * @return
	 */
	public static String timeToFormatchat(LocalDateTime date) {
		long timeStamp = date.toEpochSecond(ZoneOffset.of("+8"));
		long curTime = System.currentTimeMillis() / (long) 1000;
		long time = curTime - timeStamp;
		if (time < 3600 * 24 && time >= 0) {
			return DateUtil.format(date, "HH:mm");
		}else if (time >= 3600 * 24 && time < 3600 * 24 * 2) {
			return "昨天 " + DateUtil.format(date, "HH:mm");
		}else if(time >= 3600 * 24 * 2 && time < 3600 * 24 * 7) {
			int weekv = LocalDateTime.now().getDayOfWeek().getValue();
			int value = date.getDayOfWeek().getValue();
			if(value > weekv) {
				return DateUtil.format(date, DatePattern.CHINESE_DATE_PATTERN);
			}else {
				String week = "";
				if(value == 1) {
					week = "星期一";
				}else if(value == 2){
					week = "星期二";
				}else if(value == 3){
					week = "星期三";
				}else if(value == 4){
					week = "星期四";
				}else if(value == 5){
					week = "星期五";
				}else if(value == 6){
					week = "星期六";
				}else if(value == 7){
					week = "星期日";
				}
				return week + " " + DateUtil.format(date, "HH:mm");
			}
		
		}else if (time >= 3600 * 24 * 7) {
			return DateUtil.format(date, DatePattern.CHINESE_DATE_PATTERN);
		} else {
			return DateUtil.format(date, "HH:mm");
		}
	}
	
}
